﻿@using Nop.Core.Domain.Shipping;

@model Logistics.Web.Models.Track.LogisticsPackageModel

@{
    // TODO: string resource
    ViewBag.Title = "Track Status";
    Layout = "~/Views/Shared/_Layout.Mobile.cshtml";
}
<div id="package-status">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(false)

        @Html.LabelFor(m => m.Id) <span> : </span>
        @Html.DisplayFor(m => m.Id)
        @Html.HiddenFor(m => m.Id)

        <div class="infoblock">
            <p>@Html.LabelFor(m => m.TrackingNumber): @Html.DisplayFor(m => m.TrackingNumber)</p>
            <p>@Html.LabelFor(m => m.CreationTime): @Html.DisplayFor(m => m.CreationTime)</p>
            <p>@Html.LabelFor(m => m.UpdatedTime): @Html.DisplayFor(m => m.UpdatedTime)</p>

            @* TODO: field title to be configurable *@
            <p>
                Number of Items for This Location :
                @if (Model.SamePickupLocationNumItems.HasValue)
                {
                    @Html.DisplayFor(m => m.SamePickupLocationNumItems)
                }
                else if (Model.SameDeliveryLocationNumItems.HasValue)
                {
                    @Html.DisplayFor(m => m.SameDeliveryLocationNumItems)
                }
            </p>

            @if (!String.IsNullOrEmpty(Model.Attribute))
            {
                <p>@T("Logistics.Track.Common.Fields.Attribute") :
                @Model.Attribute
            </p>
            }

            @if (!String.IsNullOrEmpty(Model.PackageNote))
            {
                <br />
                <p>@T("Logistics.Track.Common.Fields.PackageNote") :
                @Model.PackageNote
            </p>
                <br />
            }

            @if (!String.IsNullOrEmpty(Model.Reference))
            {
                <p style="color:red">
                    @T("Logistics.Track.Common.Fields.Reference") :
                @Model.Reference
            </p>
            }
        </div>

        <p>@Html.LabelFor(m => m.Status):@(((ShippingStatus)(Model.Status)).ToString())</p>
        <div>@Html.HiddenFor(m => m.Status)</div>

        if (Model.StatusValues != null && Model.StatusValues.Count > 0)
        {
            <div class="buttonblock-wrapper package-action">
                <div class="buttonblock">
                    <p>Select action for this package:</p>
                    @foreach (var s in Model.StatusValues)
                    {
                        <input type="button" value="@s.Text" data-val="@s.Value" data-name="@Html.NameFor(x => x.SelectedStatus)" class="button button-grey" />
                    }
                    @if (Model.FailedResponses != null && Model.FailedResponses.Count > 0)
                    {
                        foreach (var r in Model.FailedResponses)
                        {
                            <input type="button" value="@r.Text" data-val="@r.Value" data-name="@Html.NameFor(x => x.SelectedFailedResponse)" class="button button-grey" />
                        }
                    }
                </div>
            </div>
        }

        if (Model.AvaliableAddressTypes.Count() > 0)
        {
            @Html.HiddenFor(model => model.VerifyAddressId);
        <div class="buttonblock-wrapper address-type">
            <div class="buttonblock">
                <p>This location is:</p>
                @foreach (var d in Model.AvaliableAddressTypes)
                {
                    <input type="button" value="@d.Text" data-val="@d.Value" data-name="@Html.FieldIdFor(model => model.SelectedAddressTypeId)" class="button button-grey" />
                }
            </div>
        </div>
        }
        if (Model.OrderBy != null)
        {
            <div class="infoblock">
                <h3>Order by</h3>
                <p>
                    @Html.DisplayFor(model => model.OrderBy)
                </p>
            </div>
        }
        <div class="infoblock pickup">

            <h3>Pickup from</h3>
            <p>
                @if (!String.IsNullOrEmpty(Model.PickUpAddress.Company))
                {
                    <span>@Html.DisplayFor(m => m.PickUpAddress.Company) - </span>
                }
                @Html.DisplayFor(m => m.PickUpAddress.FirstName) @Html.DisplayFor(m => m.PickUpAddress.LastName)
            </p>
            <p>
                @Html.LabelFor(m => m.PickUpAddress.CellPhoneNumber): @Html.DisplayFor(m => m.PickUpAddress.CellPhoneNumber)
            </p>
            @if (!String.IsNullOrEmpty(Model.PickUpAddress.PhoneNumber))
            {
                <p>
                    @Html.LabelFor(m => m.PickUpAddress.PhoneNumber)<span>: @Html.DisplayFor(m => m.PickUpAddress.PhoneNumber)</span>
                </p>
            }
            <p>
                @Html.DisplayFor(m => m.PickUpAddress.Address2)
                @Html.DisplayFor(m => m.PickUpAddress.Address1)
                @Html.DisplayFor(m => m.PickUpAddress.City)
                @Html.DisplayFor(m => m.PickUpAddress.ZipPostalCode)
            </p>
            <a href="tel:@Html.DisplayFor(m => m.PickUpAddress.CellPhoneNumber)" class="button-grey">Call Cellphone @Html.DisplayFor(m => m.PickUpAddress.CellPhoneNumber)</a>
            @if (!String.IsNullOrEmpty(Model.PickUpAddress.PhoneNumber))
            {
                <a href="tel:@Html.DisplayFor(m => m.PickUpAddress.PhoneNumber)" class="button-grey">Call Secondary @Html.DisplayFor(m => m.PickUpAddress.PhoneNumber)</a>
            }
        </div>

        <div class="infoblock delivery">
            <h3>Deliver to</h3>
            <p>
                @if (!String.IsNullOrEmpty(Model.DeliveryAddress.Company))
                {
                    <span>@Html.DisplayFor(m => m.DeliveryAddress.Company) - </span>
                }
                @Html.DisplayFor(m => m.DeliveryAddress.FirstName) @Html.DisplayFor(m => m.DeliveryAddress.LastName)
            </p>
            <p>
                @Html.LabelFor(m => m.DeliveryAddress.CellPhoneNumber): @Html.DisplayFor(m => m.DeliveryAddress.CellPhoneNumber)
            </p>
            @if (!String.IsNullOrEmpty(Model.DeliveryAddress.PhoneNumber))
            {
                <p>
                    @Html.LabelFor(m => m.DeliveryAddress.PhoneNumber)<span>: @Html.DisplayFor(m => m.DeliveryAddress.PhoneNumber)</span>
                </p>
            }

            @Html.DisplayFor(m => m.DeliveryAddress.Address2)
            @Html.DisplayFor(m => m.DeliveryAddress.Address1)
            @Html.DisplayFor(m => m.DeliveryAddress.City)
            @Html.DisplayFor(m => m.DeliveryAddress.ZipPostalCode)
            <a href="tel:@Html.DisplayFor(m => m.DeliveryAddress.CellPhoneNumber)" class="button-grey">Call Cellphone @Html.DisplayFor(m => m.DeliveryAddress.CellPhoneNumber)</a>
            @if (!String.IsNullOrEmpty(Model.DeliveryAddress.PhoneNumber))
            {
                <a href="tel:@Html.DisplayFor(m => m.DeliveryAddress.PhoneNumber)" class="button-grey">Call Secondary @Html.DisplayFor(m => m.DeliveryAddress.PhoneNumber)</a>
            }
        </div>

        <div class="buttons">
            @Html.ActionLink("Go To Plan", "PlannedRouteList", new { id = Model.PlanId }, new { @class = "button-grey" })
        </div>

        <script type="text/javascript">
            function PickupMapLink() {
                return 'http://maps.google.com/maps?q=' + escape("@Html.DisplayFor(m => m.PickUpAddress.Address1)+@Html.DisplayFor(m => m.PickUpAddress.City)+@Html.DisplayFor(m => m.PickUpAddress.StateProvinceName)+@Html.DisplayFor(m => m.PickUpAddress.CountryName)");
            }
            function DeliveryMapLink() {
                return 'http://maps.google.com/maps?q=' + escape("@Html.DisplayFor(m => m.DeliveryAddress.Address1)+@Html.DisplayFor(m => m.DeliveryAddress.City)+@Html.DisplayFor(m => m.DeliveryAddress.StateProvinceName)+@Html.DisplayFor(m => m.DeliveryAddress.CountryName)");
            }
            $(document).ready(function () {
                var link = PickupMapLink();
                $('.infoblock.pickup').append('<p><a href="' + link + '" class="button-grey" target="_blank">Map</a></p>');
                link = DeliveryMapLink();
                $('.infoblock.delivery').append('<p><a href="' + link + '" class="button-grey" target="_blank">Map</a></p>');


                $(".buttonblock-wrapper.package-action input").click(function () {
                    $("#package-action").remove();
                    $(this).after("<input id='package-action' type='hidden' name='" + $(this).attr("data-name") + "' value='" + $(this).attr("data-val") + "' />");
                    @if (Model.AvaliableAddressTypes.Count > 0) {
                    //Show address type options
                    <text>
                    var packageActionWrapper = $(".buttonblock-wrapper.package-action");
                    var addressTypeWrapper = $(".buttonblock-wrapper.address-type");
                    packageActionWrapper.stop().animate({ height: 0 });
                    addressTypeWrapper.stop().animate({ height: addressTypeWrapper.children().outerHeight(true) });
                    </text>
                } else {
                    //Submit form directly
                    <text>
                    $(this).closest("form").submit();
                    </text>
                }
                });
                $(".buttonblock-wrapper.address-type input").click(function () {
                    $("#address-type-action").remove();
                    $(this).after("<input id='address-type-action' type='hidden' name='" + $(this).attr("data-name") + "' value='" + $(this).attr("data-val") + "' />");
                    $(this).closest("form").submit();
                });
            });
        </script>
    }
</div>
